package com.imooc.bilibili.api;

import com.imooc.bilibili.api.support.UserSupport;
import com.imooc.bilibili.constant.AuthRoleConstant;
import com.imooc.bilibili.domain.JsonResponse;
import com.imooc.bilibili.domain.UserMoments;
import com.imooc.bilibili.domain.annotation.ApiLimitedRole;
import com.imooc.bilibili.domain.annotation.DataLimited;
import com.imooc.bilibili.service.UserMomentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserMomentsController {

    @Autowired
    private UserMomentsService userMomentsService;

    @Autowired
    private UserSupport userSupport;

    /**
     * 新增用户动态
     * @param userMoments
     * @return
     * @throws InterruptedException

     */
    // @ApiLimitedRole(limitedRoleCodeList = {AuthRoleConstant.ROLE_LV0})
    // @DataLimited
    @PostMapping("/user-moments")
    public JsonResponse<String> addUserMoments(@RequestBody UserMoments userMoments) {
        Long userId = userSupport.getCurrentUserId();
        // Long userId = userMoments.getUserId();
        userMoments.setUserId(userId);
        userMomentsService.addUserMoments(userMoments);
        return JsonResponse.success();
    }

    /**
     * 获取用户订阅的动态
     * @return
     */
    @GetMapping("/user-subscribed-moments")
    public JsonResponse<List<UserMoments>> getUserSubscribedMoments(){
        Long userId = userSupport.getCurrentUserId();
        // Long userId = 25L;
        List<UserMoments> result = userMomentsService.getUserSubscribedMoments(userId);
        return new JsonResponse<>(result);
    }

}
